package com.repair.controller;

import com.repair.service.RepairmanLocationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/location")
public class RepairmanLocationController {

    @Autowired
    private RepairmanLocationService repairmanLocationService;

    @PutMapping("/repairman/{repairmanId}")
    public ResponseEntity<?> updateLocation(
            @PathVariable Long repairmanId,
            @RequestBody Map<String, Double> location) {
        repairmanLocationService.updateLocation(
                repairmanId,
                location.get("latitude"),
                location.get("longitude")
        );
        return ResponseEntity.ok().build();
    }

    @GetMapping("/repairman/{repairmanId}")
    public ResponseEntity<?> getLocation(@PathVariable Long repairmanId) {
        return ResponseEntity.ok(repairmanLocationService.getRepairmanLocation(repairmanId));
    }

    @PutMapping("/repairman/{repairmanId}/status")
    public ResponseEntity<?> updateStatus(
            @PathVariable Long repairmanId,
            @RequestBody Map<String, Integer> request) {
        repairmanLocationService.updateStatus(repairmanId, request.get("status"));
        return ResponseEntity.ok().build();
    }
} 